﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CompanyBussiness;

namespace Website.admin.Control
{
    public partial class cListProperty : System.Web.UI.UserControl
    {

        ProductManagement proMana = new ProductManagement();
        LanguagesManagement languageMana = new LanguagesManagement();
        CompanyBussiness.TypeProduct typeProduct;
        CompanyBussiness.TypeProperty typeProperty;
        CompanyBussiness.Property property;
        CompanyBussiness.Language language;
        CompanyBussiness.Product product;
        CheckValid cv = new CheckValid();       
        int STRID;
        string error = "";
        string modulCode;
        int idPropertyOut;

        protected void Page_Load(object sender, EventArgs e)
        {
            string re = Request.Url.ToString();

            if (Request[CONST.QUERYSTRING_TYPE_PROPERTY] == null)
            {
                
            }
            else
            {
                this.LoadGrid();
            }
        }

        protected void LoadGrid()
        {
            STRID = int.Parse(Request[CONST.QUERYSTRING_TYPE_PROPERTY].ToString());

            gridProperty.DataSource = proMana.GetPropertyByTypeID(STRID);
            gridProperty.DataBind();

            if (proMana.GetPropertyByTypeID(STRID).Count() == 0)
            {
                lbNodes.Text = "Hiện chưa có mô tả cho thuộc tính con nào";
            }
            else
                lbNodes.Text = "";
        }

        protected void btnEdit_Command(object sender, CommandEventArgs e)
        {
            if (e.CommandName == "Edit")
            {
                Session[CONST.SESSION_PROPERTY] = Convert.ToInt32(e.CommandArgument);
                try
                {
                    
                    Response.Cookies[CONST.ACTION][CONST.COOKIES_ACTION_NAME] = "CreatProperty";
                    Response.Redirect("Administrator.aspx?" + CONST.ACTION + "=CreatProperty&" + CONST.QUERYSTRING_PROPERTY + "=" + Session[CONST.SESSION_PROPERTY].ToString());

                }
                catch (Exception)
                {

                }
            }
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            STRID = int.Parse(Request[CONST.QUERYSTRING_TYPE_PROPERTY].ToString());

            //Quay lai trang san pham
            Response.Cookies[CONST.ACTION][CONST.COOKIES_ACTION_NAME] = "CreateProduct";
            Response.Cookies[CONST.ACTION][CONST.COOKIES_ACTION_TYPE] = "UpdateProduct";
            Response.Redirect("Administrator.aspx?" + CONST.ACTION + "=CreateProduct&" + CONST.SESSION_PRODUCT_ID + "=" + proMana.GetTypePropertyById(STRID).ProductID.ToString()  + "&Mod=MPRODUCT");
        }

        protected void btnProperty_Click(object sender, EventArgs e)
        {
            STRID = int.Parse(Request[CONST.QUERYSTRING_TYPE_PROPERTY].ToString());
            //Sang trang tao moi mot thuoc tinh con
            Response.Cookies[CONST.ACTION][CONST.COOKIES_ACTION_NAME] = "CreatProperty";
            Response.Redirect("Administrator.aspx?" + CONST.ACTION + "=CreatProperty&" + CONST.QUERYSTRING_TYPE_PROPERTY + "=" + STRID);
        }
    }
}